import { getServiceInfo, getServiceProveData, getServiceStatus, getServiceType, saveServiceInfo, saveCompanyProveData } from '@/api/serviceinfo'
import { getToken, setToken, removeToken } from '@/utils/auth'

const register = {
  state: {
    token: getToken(),
    pub_key: '',
    acc_key: '',
    expire_time: '',
    name: '',
    avatar: '',
    roles: []
  },

  mutations: {
    SET_PUBKEY: (state, encryption) => {
      state.pub_key = encryption.pub_key
      state.acc_key = encryption.acc_key
      state.expire_time = encryption.expire_time
    },
    SET_TOKEN: (state, token) => {
      state.token = token
    },
    SET_NAME: (state, name) => {
      state.name = name
    },
    SET_AVATAR: (state, avatar) => {
      state.avatar = avatar
    },
    SET_ROLES: (state, roles) => {
      state.roles = roles
    }
  },

  actions: {
    // Login({ commit }, userInfo) {
    //   return new Promise((resolve, reject) => {
    //     console.log('获取token去喽', userInfo.acc_key, userInfo.passwordEncrypt)
    //     login(userInfo.acc_key, userInfo.passwordEncrypt).then(response => {
    //       const data = response.data
    //       const state = data.service_info_status
    //       console.log('路由', data)
    //       setToken(data.token)
    //       commit('SET_TOKEN', data.token)
    //       resolve(state)
    //     }).catch(error => {
    //       reject(error)
    //     })
    //   })
    // },
    // 获取服务商信息
    GetServiceInfo({ commit, state }) {
      return new Promise((resolve, reject) => {
        getServiceInfo(state.token).then(response => {
          const data = response.data.data
          console.log(data)
          resolve(data)
        }).catch(error => {
          reject(error)
        })
      })
    }
  }
}

export default user
